#pragma once
#include "cocos2d.h"
USING_NS_CC;

class CCScore : public CCObject
{
public:
	CCScore(void)
	{
		m_score = 0;
	};
	~CCScore(void){};
	char* numberToString(int number)
	{
		char szTmp[100]={0};
		int n = number;
		int i=0;
		do 
		{
			int p = n%10;
			szTmp[i] = (char)(p+48);
			i++;
		} while ((n=n/10)!=0);

		int len = i+1;
		char* pRet = (char*)malloc(len);
		for(int j=0;j<len;j++)
		{
			*(pRet+j) = szTmp[--i];
		}
		pRet[len] = '\0';
		printf("%s",pRet);
		return pRet;
	}
	void showScore(CCNode* pTarget, CCPoint position, int score)
	{
		char* pScore = numberToString(score);
		CCLabelAtlas* pLabel = CCLabelAtlas::create(pScore,"number_ranking_001.png",32,42,'0');
		pLabel->setPosition(position);
		pTarget->addChild(pLabel,0,1200);

		CCSpawn* pSqawn = CCSpawn::create(CCMoveTo::create(1.0,ccp(position.x,position.y+20)),CCFadeTo::create(1.0,0),NULL);
		CCCallFuncND* pRemove = CCCallFuncND::create(pLabel,callfuncND_selector(CCScore::removeLabel),pTarget);
		CCSequence*pSeq = CCSequence::create(pSqawn,pRemove,NULL);
		pLabel->runAction(pSeq);
	}
	void removeLabel(CCNode* pTarget, void* params)
	{
		CCLayer* pLayer = (CCLayer*)params;
		pLayer->removeChild(pTarget);
	}
	void showTotalScore(CCNode* pTarget, CCPoint position)
	{
		char* pScore = numberToString(m_score);
		CCLabelAtlas* pLabel = (CCLabelAtlas*)pTarget->getChildByTag(1201);
		if(pLabel==NULL)
		{
			pLabel = CCLabelAtlas::create(pScore,"number_ranking_001.png",32,42,'0');
			pLabel->setPosition(position);
			pLabel->setScale(0.6);
			pTarget->addChild(pLabel,0,1201);

		} 
		else 
		{
			pLabel->setString(pScore);
		}
	}

	void addScore(int score)
	{
		m_score+=score;
	}
private:
	int m_score;
};

